<?php
$mangaTitle = $model->page->chapter->manga->title;
$chapterTitle = $model->page->chapter->title;
$breadcrumbs = array(
	$mangaTitle=>array('manga/view', 'id'=>$model->page->chapter->mangaId),
	$chapterTitle=>array('chapter/view', 'id'=>$model->page->chapterId),
	$model->value,
);
$this->breadcrumbs = $breadcrumbs;

$this->menu = array(
	array('label'=>'List Upload', 'url'=>array('index')),
	array('label'=>'Upload', 'url'=>array('create')),
	array('label'=>'Update Upload', 'url'=>array('update', 'id'=>$model->id)),
	array(
		'label'=>'Delete Upload',
		'url'=>'#',
		'linkOptions'=>array(
			'submit'=>array(
				'delete',
				'id'=>$model->id
			),
			'confirm'=>'Are you sure you want to delete this item?'
		)
	),
	array('label'=>'Manage Upload', 'url'=>array('admin')),
);
?>

<h1>
	<div class="right small top bottom">
		View:
		<?php
		$formatter = Yii::app()->numberFormatter;
		echo $formatter->format('#,##0', $model->viewCount);
		?>&times;
	</div>

	<?php
	$page = $model->page->humanSequence;
	$lang = $model->value;
	echo "$mangaTitle - $chapterTitle Chapter - Page $page - $lang";
	?>
</h1>

<div class="view">
	<?php if (!Yii::app()->user->isGuest && Yii::app()->user->id == 1): ?>
		<div class="right">
			<?php
			$baseUrl = Yii::app()->request->baseUrl . '/images/toolbars';
			$deleteConfirm = 'Are you sure you want to delete this item?';
			$deleteLabel = "<img src=\"$baseUrl/cross-script.png\" />";
			$properties = array(
				'items'=>array(
					array(
						'label'=>"<img src=\"$baseUrl/pencil.png\" />",
						'url'=>array('language/update', 'id'=>$model->id),
						'linkOptions'=>array('title'=>'Update'),
					),
					array(
						'url'=>'#',
						'linkOptions'=>array(
							'submit'=>array(
								'language/delete',
								'id'=>$model->id
							),
							'confirm'=>$deleteConfirm,
							'title'=>'Delete',
						),
						'label'=>$deleteLabel,
						'visible'=>Yii::app()->user->id == 1,
					),
				),
				'htmlOptions'=>array(
					'class'=>'operations',
				),
				'encodeLabel'=>false,
			);
			$this->widget('zii.widgets.CMenu', $properties);
			?>
		</div>
	<?php endif; ?>

	<div>
		<?php if ($model->dialects): ?>
			Available translations for this page:
			<?php
			$total = count($model->dialects);
			for ($index = 0; $index < $total; $index++) {
				$url = array(
					'translation/create',
					'languageId'=>$model->id,
					'dialect'=>$model->dialects[$index],
				);
				$htmlOptions = array();
				echo CHtml::link($model->dialects[$index], $url, $htmlOptions);
				echo $this->loadHumanGlue($index, $total);
			}
			echo '.';
			?>
		<?php else: ?>
			Sorry, there's no translation for this page.
		<?php endif; ?>
	</div>

	<div>
		<?php if ($model->alternatives): ?>
			This page also available in:
			<?php
			$total = count($model->alternatives);
			foreach ($model->alternatives as $index=>$alternative) {
				$url = array(
					'language/view',
					'id'=>$alternative->id,
				);
				$htmlOptions = array();
				echo CHtml::link($alternative->value, $url, $htmlOptions);
				echo $this->loadHumanGlue($index, $total);
			}
			echo '.';
			?>
		<?php else: ?>
			Sorry, there's no alternative for this page.
		<?php endif; ?>
	</div>

</div>

<div class="right">
	<?php
	$action = array('language/view');
	echo CHtml::beginForm($action, 'get');
	$htmlOptions = array('class'=>'page-nav');
	echo CHtml::dropDownList('id', $model->id, $navList, $htmlOptions);
	echo ' ';
	echo CHtml::submitButton('Go');
	echo CHtml::endForm();
	?>
</div>

<div class="clear"></div>

<div class="view center">
	<?php
	$src = $model->fileUrl;
	$alt = '';
	$htmlOptions = array('id'=>'mangascan');
	echo CHtml::image($src, $alt, $htmlOptions);
	?>
</div>

<div class="right">
	<?php
	$action = array('language/view');
	echo CHtml::beginForm($action, 'get');
	$htmlOptions = array('class'=>'page-nav');
	echo CHtml::dropDownList('id', $model->id, $navList, $htmlOptions);
	echo ' ';
	echo CHtml::submitButton('Go');
	echo CHtml::endForm();
	?>
</div>

<div class="clear"></div>

<div class="prepend-top last">

	<h1>Submit Translation</h1>

	<?php
	$data = array(
		'model'=>$translation,
	);
	$this->renderPartial('application.views.translation._form', $data);
	?>

</div>

<?php
Yii::app()->clientScript->registerScript(
	'page-nav-submitter',
	'
    $(".page-nav").change(
        function() {
            $(this).parent().submit();
        }
    );
    '
);
?>
